package org.dei.perla.test.llqruntime.simulator;

import org.dei.perla.sys.query.llqruntime.datastructures.*;
import org.dei.perla.test.llqruntime.simulator.DeviceMockup;
import org.dei.perla.utils.pipe.*;

/**
 *
 */
public class SingleSamplingActivity extends Thread{

	//Time to sleep
	private long pMillisecs = 10000;
	
	//Pipe in uscita
	private Pipe<Record> pOutPipe;
	
	//Device da cui "spillare" il record
	private DeviceMockup pDevice;
	
	//Costruttore
	public SingleSamplingActivity(DeviceMockup parDevice) {
		this.pDevice = parDevice;
		pOutPipe = new Pipe<Record>("Pipe");
		this.pOutPipe.start();
	}
	
	//Metodo che produce il record
	public void run() {
	
		while (true) {
			this.pOutPipe.enqueue(pDevice.generateRecord());
			try {
				sleep(pMillisecs);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
	//Setter nuova frequenza di produzione
	public void setSamplingFrequency(long parMillisecs) {
		this.pMillisecs = parMillisecs;
		
	}
	
	public Pipe<Record> getPipe() {
		return this.pOutPipe;
	}
}
